package com.abaaba.project2.controller;

import com.abaaba.project2.aspect.Log;
import com.abaaba.project2.bean.Admin;
import com.abaaba.project2.bean.bo.AdminListBo;
import com.abaaba.project2.bean.vo.AdminListVo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.service.AdminSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/admin")
public class AdminSystemController {

    @Autowired
    AdminSystemService adminSystemService;

    @RequestMapping("/list")
    public BaseRespVo showAdminList(AdminListBo adminListBo)
    {
        AdminListVo adminListVo = adminSystemService.showAdminList(adminListBo);

        return BaseRespVo.ok(adminListVo);
    }

    @RequestMapping("/create")
    @Log
    public BaseRespVo createAdmin(@RequestBody Admin admin)
    {
        Admin adminVo = adminSystemService.createAdmin(admin);

        if (adminVo == null)
        {
            return BaseRespVo.fail("不允许重名");
        }

        return BaseRespVo.ok(adminVo);
    }

    @RequestMapping("/update")
    @Log
    public BaseRespVo updateAdmin(@RequestBody Admin admin)
    {
        Admin adminVo = adminSystemService.updateAdmin(admin);

        if (adminVo == null)
        {
            return BaseRespVo.fail("不允许重名");
        }

        return BaseRespVo.ok(adminVo);
    }

    @RequestMapping("/delete")
    @Log
    public BaseRespVo deleteAdmin(@RequestBody Admin admin)
    {
        adminSystemService.deleteAdmin(admin);

        return BaseRespVo.ok();
    }



}
